package com.example.demo.Controller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

@Controller
 @RequestMapping("/login")
@CrossOrigin(origins = "*")//允许所有同源访问，防止出现跨域问题
public class LoginController {
    @GetMapping("/")
    public ModelAndView showLoginForm() {
        return new ModelAndView("login");
    }

    // 处理登录请求
    @PostMapping("/submit")
    public ModelAndView processLogin(String username, String password) {
        // 这里添加你的登录逻辑，比如验证用户名和密码
        // 假设我们这里只是简单地返回一个视图
        ModelAndView modelAndView = new ModelAndView("welcome");
        modelAndView.addObject("message", "登录成功！");
        return modelAndView;
    }
}
